﻿using Core.Framework.Distributed.Model;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Core.Framework.Distributed
{
    /// <summary>
    /// 锁
    /// </summary>
    public interface ILock
    {

        /// <summary>
        /// 申请锁
        /// 如果锁被占用则反馈假
        /// 异步执行不阻塞主线程执行
        /// </summary>
        /// <param name="entity">申请参数</param>
        /// <param name="success">获取锁之后执行</param>
        /// <param name="fail">获取锁失败之后执行</param>
        Task<ApplyLockContext> ApplyAsync(ApplyLockEntity entity, Action success, Action fail);


        /// <summary>
        /// 申请锁
        /// 如果锁被占用则等待获取锁
        /// 异步执行不阻塞主线程执行
        /// </summary>
        /// <param name="entity">申请参数</param>
        /// <param name="success">获取锁之后执行</param>
        Task<ApplyLockContext> ApplyWaitAsync(ApplyLockEntity entity, Action success);

    }
}
